from multiprocessing import Pool, Manager
from queue import Queue
from tool import *
from config import *
from other_task import *
from papi import fanyi_adpro
from sql import sqlseverDB
from shop import Shop,PHShop
import sys,traceback,time,other_task
taskid=int(sys.argv[1])
ms = sqlseverDB('{SQL Server}', SQL_SERVER, 'sumaitongpol', SQL_USER, SQL_PWD)
rs_task=ms.ExecQuerydict('select * from task where id=?',(taskid,))

# 全局配置日志，既写入文件又输出到控制台
logger = logging.getLogger()
logger.setLevel(logging.INFO)  # 设置日志级别
# 创建文件处理器 (Handler)
task_info=rs_task[0]
rw_name=task_info['tName']
log_path=f'D:/Web/Gtupdate/GTLOG/{rw_name}{getTimeStr()}.log'
file_handler = logging.FileHandler(log_path, mode='a', encoding='utf-8')
ms.ExecNoQuery('update task set logPath=? where id=?',(log_path,taskid))

# 创建控制台处理器 (Handler)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)

# 设置日志格式
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)

# 将处理器添加到 logger 对象
logger.addHandler(file_handler)
logger.addHandler(console_handler)

def process_shop(tid,cur_shop,fun_name,queue):

    dp_basic_info=cur_shop.basic_info
    browserID, dpname = dp_basic_info['BrowserID'], dp_basic_info['DpName']
    rw_name=Task_Name_dict[tid]
    try:
        logging.info(f'bid:{browserID}, 浏览器:{dpname},开始{rw_name}...') 
        res=cur_shop.start_task(tid)
        logging.info(f'浏览器ID:{browserID}, 店铺ID:{dpname},结束任务{res}')
    except Exception as e:
        logging.error(f'bid:{browserID}, 出现错误: {e}')
        traceback.print_exc()
        time.sleep(3)
    # 将采集后的结果添加到队列
    queue.put(1)


def update_task_status(ms,queue, task_count,tid,hid):
    """更新任务状态"""
    remaining_tasks = task_count - queue.qsize()
    ms.ExecNoQuery('update [task] set [tcount]=?,LastHouTaiID=? where [id]=?', (remaining_tasks,hid,tid))
    rw_name=Task_Name_dict[tid]

    logging.info(f'{rw_name}任务队列剩余: {remaining_tasks}\n')

def on_task_complete(ms,queue, task_count,tid,hid):
    """任务完成时的回调函数"""
    update_task_status(ms,queue, task_count,tid,hid)


def main():
    taskid=int(sys.argv[1])
    tb_name_pt_dict={
        '虾皮':'HouTai',
        '波兰':'HouTai_ALG',
        '泰国虾皮':'HouTai_TH',
        '阿里巴巴':'S1688Account'
    }
    tb_name=tb_name_pt_dict[task_info['pt']]
    iszd=task_info['iszd']
    last_tid=task_info['LastHouTaiID']
    shopClass=task_info['ShopClass']
    fun_name=task_info['FuncName']
    isMulti=task_info['isMulti']

    if taskid==11:
        aff_dd=ms.ExecNoQuery('update houtai set order_updated=0 where order_updated!=0')
        logging.info(f'将 {aff_dd} 个虾皮订单任务完成状态置0')
    
    if taskid==24:
        gender_count_map={
            1:20,
            2:20,
            3:20,
            4:100
        }
        pro_move={}
        to_country_list=['马来西亚']

        for to_c in to_country_list:
            sql_str_zy1=f'''
                    select distinct xpo.random_code from ShopeeOrder xpo
                        join S1688Pro sp on xpo.random_code=sp.random_code
                        and sp.is_cj=1
                        AND NOT EXISTS (
                                SELECT 1 FROM ShopeeAdsMove c
                                WHERE xpo.random_code = c.random_code
                                AND c.to_country = '{to_c}'
                            )
                '''
            aff_in=0
            rs_zy1=tms.ExecQuerydict(sql_str_zy1)
            for rzy in rs_zy1:
                cur_rcode=rzy['random_code']
                kw_gender=1
                
                rsm1=tms.ExecQuery('select count(*) from ShopeeAdsMove where random_code=? and to_country=?',(cur_rcode,to_c))
                if rsm1[0][0]==0:
                    pdtata={
                        'to_country':to_c,
                        'random_code':cur_rcode,
                        'data_from':'印尼出单产品',
                        'keword_gender':kw_gender
                    }

                    zzds=list(pdtata.keys())
                    zparas=list(pdtata.values())

                    aff_in+=tms.merge_into('ShopeeAdsMove',zzds,zparas,['random_code','to_country'],True)
            logging.info(f'国家:《{to_c}》,印尼出单产品新增:{aff_in}个测品')


        for to_c in to_country_list:
            aff_in=0
            cur_zd_cs=Country_Sql_Zd_Map[to_c]
            zd_dc_bid=cur_zd_cs['zd_dc_bid']
            session=requests.session()
            session.headers=DS_Headers
            for gender in range(1,5):
                rs_has_moved=ms.ExecQuery('select count(*) from ShopeeAdsMove where data_from=? and is_draft=0 and to_country=? and keword_gender=?',('1688可广告测品',to_c,gender))
                move_count=rs_has_moved[0][0]
                need_count=gender_count_map[gender]
                if move_count<gender_count_map[gender]:
                    
                    sql_str_zy2=f'''WITH Filtered AS (
                                        SELECT 
                                            p.random_code,
                                            p.copyright_th,
                                            p.from_keywords,
                                            p.keword_gender,
                                            ROW_NUMBER() OVER (PARTITION BY p.from_keywords ORDER BY NEWID()) AS rn
                                        FROM s1688pro p 
                                        WHERE p.is_cj = 1
                                        AND p.keword_gender={gender}
                                        AND (p.shop_name LIKE '%公司%' OR p.shop_name LIKE '%厂%')
                                        AND p.price BETWEEN 20 AND 100
                                        AND p.rating_star >= 4
                                        AND p.historical_sold >= 50
                                        AND p.{zd_dc_bid} is null
                                        AND (copyright_th='大数据不侵权' or copyright_th is null)
                                        AND NOT EXISTS (
                                            SELECT 1 FROM Blacklist b
                                            WHERE b.word_language = '中文'
                                            AND p.pname LIKE '%' + b.word_blacklist + '%'
                                        )
                                        AND NOT EXISTS (
                                            SELECT 1 FROM Blacklist b
                                            WHERE b.word_language = '印尼语'
                                            AND p.yntitle LIKE '%' + b.word_blacklist + '%'
                                        )
                                        AND NOT EXISTS (
                                            SELECT 1 FROM Blacklist b
                                            WHERE b.word_language = '泰语'
                                            AND p.thtitle LIKE '%' + b.word_blacklist + '%'
                                        )
                                        AND NOT EXISTS (
                                            SELECT 1 FROM ShopeeAdsMove c
                                            WHERE p.random_code = c.random_code
                                            AND c.to_country = '{to_c}'
                                        )
                                    )
                                SELECT TOP {need_count}
                                    random_code, 
                                    copyright_th,
                                    keword_gender
                                FROM Filtered
                                ORDER BY rn;
                                '''
                    rs_zy2=tms.ExecQuerydict(sql_str_zy2)

                    for rzy in rs_zy2:
                        cur_rcode=rzy['random_code']
                        kw_gender=rzy['keword_gender']
                        
                        rsm2=tms.ExecQuery('select count(*) from ShopeeAdsMove where random_code=? and to_country=?',(cur_rcode,to_c))
                        if rsm2[0][0]==0:
                            pdtata={
                                'to_country':to_c,
                                'random_code':cur_rcode,
                                'data_from':'1688可广告测品',
                                'keword_gender':kw_gender
                            }

                            zzds=list(pdtata.keys())
                            zparas=list(pdtata.values())

                            aff_in+=tms.merge_into('ShopeeAdsMove',zzds,zparas,['random_code','to_country'],True)

                    logging.info(f'国家:《{to_c}》,等级:{gender},广告测品,需补充:{need_count},实际补充:{aff_in}个')
                    

            logging.info(f'国家:《{to_c}》,开始翻译产品标题和描述')

            sql_str1=f'''SELECT p.id,p.itemid, p.random_code, p.pname, p.attributes,p.is_fy_ensku
                        FROM S1688Pro p
                        JOIN ShopeeAdsMove m
                            ON p.random_code = m.random_code
                        WHERE m.to_country = '{to_c}'
                        AND m.is_fy = 0
                    '''
            rs1=tms.ExecQuery(sql_str1)
            if len(rs1)==0:
                logging.info(f'国家:《{to_c}》,测品无需翻译')
            else:
                logging.info(f'国家:《{to_c}》,共有 {len(rs1)} 个标题描述待生成')
                with thddd.ThreadPoolExecutor(max_workers=10) as t:
                    tasks=[]
                    for dj,r1 in enumerate(rs1,start=1):
                        tasks.append(t.submit(fanyi_adpro,to_c,dj,r1))

                    for tjjj,t0 in enumerate(thddd.as_completed(tasks),start=1):
                        try:
                            res=t0.result()
                        except Exception as e:
                            traceback.print_exc()
                            print(f'线程错误 => {e}')
                        logging.info(f'本次剩余任务队列:{len(rs1)-tjjj}/{len(rs1)}')
                
            sql_str2=f"select random_code,keword_gender from ShopeeAdsMove where to_country='{to_c}' and is_fy=1 and is_draft=0 order by keword_gender"
            rs2=tms.ExecQuery(sql_str2)
            pro_move[to_c]=rs2
            logging.info(f'国家:《{to_c}》,提取到:{len(pro_move[to_c])} 个测品')

            
    if taskid==26:
        aff_reset_kol=ms.ExecNoQuery('update ShopeeKOL set yao_qing_bid=null where yao_qing_bid is not null and is_yao_qing=0')
        logging.info(f'任务:《{rw_name}》,将 {aff_reset_kol} 个达人状态重置为可邀请')

    if taskid==28:
        aff_pdc=ms.ExecNoQuery('update S1688Pro set distribution_export_bid=null,distribution_export_shopid=null where distribution_export_bid is not null and is_distribution_export=0')
        aff_ml_pdc=ms.ExecNoQuery('update S1688Pro set ml_dc_bid=null,ml_dc_shopid=null where ml_dc_bid is not null and is_ml_big_dc=0')
        logging.info(f'任务:《{rw_name}》,印尼大数据重置:{aff_pdc},马来西亚大数据重置:{aff_ml_pdc}')
        sss_json={'status':0}
        with open('状态锁/s1688大数据导出.json','w',encoding='utf-8') as f:
            json.dump(sss_json,f,ensure_ascii=False,indent=4)
    
    if taskid==31:
        aff_pdc=ms.ExecNoQuery('update S1688Pro set th_dc_bid=null,th_dc_shopid=null where th_dc_bid is not null and is_th_big_dc=0')
        logging.info(f'任务:《{rw_name}》,将 {aff_pdc} 个1688产品状态重置为可泰国侵权导出')
        sss_json={'status':0}
        with open('状态锁/s1688泰国侵权测试导出.json','w',encoding='utf-8') as f:
            json.dump(sss_json,f,ensure_ascii=False,indent=4)
    
    if taskid in (40,41,42,43,44,45):
        pro_big_data_map={}
        tcountry_list=['印尼','马来西亚']
        for cur_gjj in tcountry_list:
            pro_big_data=get_big_data_rcode_list(cur_gjj,taskid)
            pro_big_data_map[cur_gjj]=pro_big_data

            print(f'任务:《{rw_name}》,国家:{cur_gjj},可发布数据:{len(pro_big_data)}')
        
    if taskid in (49,50):
        aff_reset=ms.ExecNoQuery(''' update Houtai set req_count=0
                        WHERE (last_end_time is null or DATEDIFF(SECOND, DATEADD(SECOND, last_end_time, '1970-01-01'),GETUTCDATE()) > 7200)
                        and req_count!=0 and is_cj_pro=1 ''')
        
        logging.info(f'任务《{rw_name}》,成功将 {aff_reset} 个马老西亚账号设置为可采集状态')
    
    if taskid==49:

        aff_zz=ms.ExecNoQuery("update keyword_1688 set is_cj=0 where is_cj=1 and language='英语' and keyword_type='选品关键词' and emarket='shopee马来' and DATEDIFF(DAY, cj_time, GETDATE()) >=5")
        logging.info(f'任务《{rw_name}》,重置 {aff_zz} 个关键词采集状态')
        sql_lm=''' select * from keyword_1688 p 
                    where is_cj=0 
                    and language='英语' 
                    and keyword_type='选品关键词' 
                    and emarket='shopee马来'
                    and size_weight_type='体积大,重量小'
                    AND NOT EXISTS (
                        SELECT 1
                        FROM Blacklist b
                        WHERE b.word_language = '英语'
                        AND p.keyword LIKE '%' + b.word_blacklist + '%'
                    ) 
                    '''
        rs_lm=ms.ExecQuerydict(sql_lm)
        task_len=5
    
    if taskid==50:

        sql_pro='''select id,url,itemid from ShopeePHADPro where is_cj=0 order by month_sold desc'''
        rs_lm=ms.ExecQuery(sql_pro)
        task_len=10

    xh_num=3
    if taskid in [2,32,46,48,51,52,53,54,55]:
        extraParam=task_info['extraParam']
        func_name=Task_Fuc_dict[taskid]
        task_func = getattr(other_task, func_name, None)

        if callable(task_func):
            logging.info(f'任务《{rw_name}》,无店铺,直接运行')
            if extraParam:
                task_func(extraParam)  # 调用函数
            else:
                task_func()
        else:
            print(f"函数 {func_name} 不存在")
    else:
        for repeat_j in range(1,xh_num):
            if taskid in (49,50):
                rs=ms.ExecQuerydict(f'select * from Houtai where req_count<{PH_MAX_REQ_COUNT} and is_cj_pro=1 order by req_count')
            elif not iszd.lower().startswith('select'):
                rs=ms.ExecQuerydict(f'select * from {tb_name} where {iszd}=1 and is_task_baned=0')
            else:
                rs=ms.ExecQuerydict(iszd.replace('count(*)','*'))
            

            rw_bids=[f"'{r['BrowserID']}'" for r in rs]
            logging.info(f'任务《{rw_name}》开启第 {repeat_j} 轮运行,共{len(rs)} 个店铺')
        
            if repeat_j==1 and not last_tid:
                aff_del_ttt=tms.ExecNoQuery(f'delete from taskStatus where task_id=? and bid not in (select BrowserID from {tb_name} where {iszd}=1 and is_task_baned=0)',(taskid,))
                aff_change_state=tms.ExecNoQuery('update taskstatus set state=0 where task_id=?',(taskid,))
                logging.info(f'任务《{rw_name}》,全部运行,删除无效店铺:{aff_del_ttt}个,重置所有任务状态:{aff_change_state} 个')

            if repeat_j>1 or last_tid:
                rs_competed=ms.ExecQuery('select bid from taskStatus where task_id=? and state=1',(taskid,))
                bid_competed=[r[0] for r in rs_competed]
                rs=[r for r in rs if r['BrowserID'] not in bid_competed]
                logging.info(f'任务《{rw_name}》第 {repeat_j} 轮运行, 排除已完成店铺:{len(bid_competed)} 个后,剩余 {len(rs)} 个未完成')
                
            if len(rs)==0:
                break
            
            task_count=len(rs)
            logging.info(f'任务《{rw_name}》,共有 {task_count} 个店铺')
            if taskid in (40,41,42,43,44,45):
                country_count_map={}
                for rr in rs:
                    ccc_gjjj=rr['Country']
                    if country_count_map.get(ccc_gjjj):
                        country_count_map[ccc_gjjj]+=1
                    else:
                        country_count_map[ccc_gjjj]=1
            
                country_qp_map={}
                for cc_gj,gj_count in country_count_map.items():
                    all_big_pros=pro_big_data_map[cc_gj]
                    cur_qp=int(len(all_big_pros)/gj_count)
                    if cur_qp>100:
                        cur_qp=100
                    if 0<cur_qp<20:
                        cur_qp=20
                    country_qp_map[cc_gj]=cur_qp
                
                logging.info(f'任务《{rw_name}》,当前国家数据分配切片情况 : {country_qp_map}')

            
            if isMulti==0 or isMulti==-1:
                for hj,r in enumerate(rs):
                    browserID,dpname,yybm,selfgj=r['BrowserID'],r['DpName'],r['YYBM'],r['Country']
                    if shopClass=='shop':
                        cur_shop=Shop(r)
                    elif shopClass=='phshop':
                        cur_shop=PHShop(r)
                    
                    if taskid==24:
                        country=r['Country']
                        cur_kw_type=r['keyword_type']
                        
                        cur_pros=pro_move.get(country)
                        if not cur_pros:
                            logging.info(f'任务:《{rw_name}》,店铺:《{dpname}》,{browserID},国家:《{country}》,总测品为空,跳过')
                            continue
                        cur_rlist=[]
                        gender_count=[0,0,0,0]
                        for prcode,pgender in cur_pros:
                            if gender_count[pgender-1]<20:
                                cur_rlist.append(prcode)
                                gender_count[pgender-1]+=1
                            if len(cur_rlist)>=50:
                                break

                        if cur_rlist:
                            
                            cur_pros=[r for r in cur_pros if r[0] not in cur_rlist]
                            pro_move[country]=cur_pros
                            logging.info(f'店铺:《{dpname}》,{browserID},国家:《{country}》,等级分布:{gender_count},提取了{len(cur_rlist)} 个测品数据,剩下可分配:{len(cur_pros)}')
                        else:
                            logging.info(f'店铺:《{dpname}》,{browserID},国家:《{country}》,没提取到测品')
                        
                        cur_shop.rocde_list=cur_rlist

                    if taskid in (40,41,42,43,44,45):
                        all_rcode_list=pro_big_data_map.get(selfgj)
                        if not all_rcode_list:
                            logging.info(f'任务:《{rw_name}》,店铺:《{dpname}》,{browserID},国家:《{selfgj}》,无数据可发布,跳过')
                            continue
                        gj_qp=country_qp_map[selfgj]
                        cur_big_rlist=all_rcode_list[hj*gj_qp:(hj+1)*gj_qp]
                        cur_shop.rocde_list=cur_big_rlist
                        logging.info(f'任务:{rw_name},店铺:《{dpname}》,{browserID},国家:《{selfgj}》提取了{len(cur_big_rlist)} 大数据')
 
                    if taskid in [49,50]:
                        task_list=rs_lm[hj*task_len:(hj+1)*task_len]
                        if not task_list:
                            break
                        cur_shop.task_list=task_list
                                                

                    logging.info(f'店铺:《{dpname}》,{browserID},开始执行任务:《{rw_name}》')

                    try:   
                        res=cur_shop.start_task(taskid)
                        logging.info(f'店铺:《{dpname}》,{browserID},执行任务结果 => {res}')
                    except Exception as e:
                        logging.info(f'店铺:《{dpname}》,{browserID},执行任务错误 => {e}')
                        traceback.print_exc()
                        time.sleep(3)
                    
                    task_count-=1
                    if not iszd.lower().startswith('select'):
                        update_task_current_state(rs[-task_count]['id'],taskid,iszd,tb_name)
                    else:
                        ms.ExecNoQuery('update [task] set [tcount]=[tcount]-1 where [id]=?',(taskid,))
                        
                    logging.info(f'《{rw_name}》剩余任务数:{task_count}\n\n')
            
            else:
                print(f'{rw_name},多进程运行,进程数:{isMulti}')
                manager = Manager()
                queue = manager.Queue()
                    # 多进程池的初始化

                with Pool(processes=isMulti) as pool:  # 根据实际情况设置并发进程数量
                    results = []
                    for hj,r in enumerate(rs):
                        browserID,dpname,yybm,selfgj=r['BrowserID'],r['DpName'],r['YYBM'],r['Country']
                        hid=r['id']
                        if shopClass=='shop':
                            cur_shop=Shop(r)
                        elif shopClass=='phshop':
                            cur_shop=PHShop(r)
                
                        if taskid==24:
                            country=r['Country']
                            cur_kw_type=r['keyword_type']
                            
                            cur_pros=pro_move.get(country)
                            if not cur_pros:
                                logging.info(f'任务:《{rw_name}》,店铺:《{dpname}》,{browserID},国家:《{country}》,总测品为空,跳过')
                                continue
                            cur_rlist=[]
                            gender_count=[0,0,0,0]
                            for prcode,pgender in cur_pros:
                                if gender_count[pgender-1]<20:
                                    cur_rlist.append(prcode)
                                    gender_count[pgender-1]+=1
                                if len(cur_rlist)>=50:
                                    break

                            if cur_rlist:
                                
                                cur_pros=[r for r in cur_pros if r[0] not in cur_rlist]
                                pro_move[country]=cur_pros
                                logging.info(f'店铺:《{dpname}》,{browserID},国家:《{country}》,等级分布:{gender_count},提取了{len(cur_rlist)} 个测品数据,剩下可分配:{len(cur_pros)}')
                            else:
                                logging.info(f'店铺:《{dpname}》,{browserID},国家:《{country}》,没提取到测品')
                            
                            cur_shop.rocde_list=cur_rlist
                        
                        if taskid in (40,41,42,43,44,45):
                            all_rcode_list=pro_big_data_map.get(selfgj)
                            if not all_rcode_list:
                                logging.info(f'任务:《{rw_name}》,店铺:《{dpname}》,{browserID},国家:《{selfgj}》,无数据可发布,跳过')
                                continue
                            gj_qp=country_qp_map[selfgj]
                            cur_big_rlist=all_rcode_list[hj*gj_qp:(hj+1)*gj_qp]
                            cur_shop.rocde_list=cur_big_rlist
                            logging.info(f'任务:{rw_name},店铺:《{dpname}》,{browserID},国家:《{selfgj}》提取了{len(cur_big_rlist)} 大数据')
                                
                        if taskid in [49,50]:
                            task_list=rs_lm[hj*task_len:(hj+1)*task_len]
                            if not task_list:
                                break
                            cur_shop.task_list=task_list
                        result = pool.apply_async(
                            process_shop, args=(taskid,cur_shop,fun_name,queue),
                            callback=lambda _,hid=hid: on_task_complete(ms,queue, task_count,taskid,hid)
                        )
                        results.append(result)

                    # 监控任务执行情况
                    pool.close()
                    for result in results:
                        result.wait()  # 等待每个进程完成，无超时限制

                    # 所有任务执行完成后继续
                    pool.join()

        
        if rw_bids:
            wstr_rwbid=','.join(rw_bids)
            rs_no_competed=ms.ExecQuery(f'select bid,bname,gname from taskStatus where task_id=? and state=0 and bid in ({wstr_rwbid})',(taskid,))
            cur_time=datetime.datetime.now()
            aff_nn=0
            err_zds=['iscl','task_id','task_name','BID','loginTime','pintai','bname','gname']
            for nn_bid,nn_bname,nn_gname in rs_no_competed:
                err_params=[0,taskid,rw_name,nn_bid,cur_time,task_info['pt'],nn_bname,nn_gname]
                aff_nn+=ms.merge_into('ErrBid',err_zds,err_params,['bid'])

            logging.info(f'任务《{rw_name}》,共记录 {aff_nn} 个执行错误的任务')


    ms.ExecNoQuery('update [task] set state=0,tcount=0,LastHouTaiID=null where [id]=?',(taskid,))
    change_task_status(taskid,0)


    if taskid == 11:
        logging.info(f'开始同步《ShopeeOrder》销售状态列...')

        # 第一步：更新所有含“在售”的 skuid，统一为“在售”
        sql_zaishou = '''
            UPDATE ShopeeOrder
            SET xiaoshouzhuangtai = '在售'
            WHERE skuid IN (
                SELECT skuid
                FROM ShopeeOrder
                WHERE xiaoshouzhuangtai = '在售'
                GROUP BY skuid
            )
            AND xiaoshouzhuangtai != '在售'
        '''
        aff1 = ms.ExecNoQuery(sql_zaishou)
        logging.info(f'《ShopeeOrder》,在售,同步 {aff1} 条记录')

        # 第二步：更新含“停售”但没有“在售”的 skuid，统一为“停售”
        sql_tingshou = '''
            UPDATE ShopeeOrder
            SET xiaoshouzhuangtai = '停售'
            WHERE skuid IN (
                SELECT skuid
                FROM ShopeeOrder
                GROUP BY skuid
                HAVING MAX(CASE WHEN xiaoshouzhuangtai = '在售' THEN 1 ELSE 0 END) = 0
                AND MAX(CASE WHEN xiaoshouzhuangtai = '停售' THEN 1 ELSE 0 END) = 1
            )
            AND xiaoshouzhuangtai != '停售'
        '''
        aff2 = ms.ExecNoQuery(sql_tingshou)
        logging.info(f'《ShopeeOrder》,停售,同步 {aff2} 条记录')


if __name__ == "__main__":
    main()

